package cn.shuangliang.contract.web;

import cn.shuangliang.contract.model.Contracthistory;
import cn.shuangliang.contract.service.HistoryService;
import cn.shuangliang.contract.util.StrUtil;
import cn.shuangliang.contract.vo.Constant;
import cn.shuangliang.contract.vo.Page;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.UUID;

/**
 * @author oldliu
 * @since 1.0
 */
public class HistoryController {
    HistoryService service=new HistoryService();
    public String index(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int pageNo=StrUtil.toInt(request.getParameter("pageNo"),1);
        String billno= StrUtil.trim(request.getParameter("billno"));
        String pname=StrUtil.trim(request.getParameter("pname"));
        Date start=StrUtil.toDate(request.getParameter("start"));
        Date end=StrUtil.toDate(request.getParameter("end"));

        Page<Contracthistory> page = service.search(pageNo, Constant.pageSize, billno, pname, start, end);
        request.setAttribute("billno",billno);
        request.setAttribute("pname",pname);
        request.setAttribute("start",start);
        request.setAttribute("end",end);
        request.setAttribute("page",page);
        return "/WEB-INF/views/history.html";
    }
    public void export(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String billno= StrUtil.trim(request.getParameter("billno"));
        String pname=StrUtil.trim(request.getParameter("pname"));
        Date start=StrUtil.toDate(request.getParameter("start"));
        Date end=StrUtil.toDate(request.getParameter("end"));
        List<Contracthistory> page = service.exportsearch(billno, pname, start, end);
//        ExportExecl.exportExcel(new String[]{"到货日期","合同编号","品种","丝度","规格","吨位","件数"},page, "到货统计.xls",response);
    }
}
